/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clases;

import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author paulo
 */
public class Contacto extends Root{

  private int id;
  private String fuente;
  private String informacion;
  private String correo;
  private String fechaEnvio;

  public Contacto() {
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getFuente() {
    return fuente;
  }

  public void setFuente(String fuente) {
    this.fuente = fuente;
  }


  public String getCorreo() {
    return correo;
  }

  public void setCorreo(String correo) {
    this.correo = correo;
  }

  public String getFechaEnvio() {
    return fechaEnvio;
  }

  public void setFechaEnvio(String fechaEnvio) {
    this.fechaEnvio = fechaEnvio;
  }

  public String getInformacion() {
    return informacion;
  }

  public void setInformacion(String informacion) {
    this.informacion = informacion;
  }
  
      /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
   @Override
    public ActionErrors validate(ActionMapping mapping,HttpServletRequest request)
    {
        ActionErrors errors = new ActionErrors();
        if(getFuente().length()  == 0){
            errors.add("fuente", new ActionMessage("errors.fuente"));
        }
        if(getInformacion().isEmpty()){
            errors.add("informacion", new ActionMessage("errors.informacion"));
        }
        if(!validarEmail(getCorreo()))
            errors.add("correo", new ActionMessage("errors.correo"));
        
        mapping.getInputForward();
        return errors;
    }
   
    public boolean validarEmail(String email) {
        String regex = "^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }

    public void clean() {
        this.fuente = "";
        this.correo = "";
        this.informacion ="";
    }
}
   

